home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Un ejercicio de presentación de texto / SysInfoScroll / SysInfoScroll.cs next >
Encoding:
Text File  |  2002-05-22  |  1.9 KB  |  57 lines

  1. //--------------------------------------------
  2. // SysInfoScroll.cs ⌐ 2001 by Charles Petzold
  3. //--------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class SysInfoScroll: Form
  9. {
  10.      readonly float cxCol;
  11.      readonly int   cySpace;
  12.  
  13.      public static void Main()
  14.      {
  15.           Application.Run(new SysInfoScroll());
  16.      }
  17.      public SysInfoScroll()
  18.      {
  19.           Text = "Informaci≤n del Sistema: Desplazamiento";
  20.           BackColor = SystemColors.Window;
  21.           ForeColor = SystemColors.WindowText;
  22.  
  23.           Graphics grfx  = CreateGraphics();
  24.           SizeF    sizef = grfx.MeasureString(" ", Font);
  25.           cxCol   = sizef.Width + SysInfoStrings.MaxLabelWidth(grfx, Font);
  26.           cySpace = Font.Height;
  27.  
  28.                // Establecer las propiedades del autodesplazamiento.
  29.  
  30.           AutoScroll = true;
  31.           AutoScrollMinSize = new Size(
  32.               (int) Math.Ceiling(cxCol + 
  33.                                  SysInfoStrings.MaxValueWidth(grfx, Font)),
  34.               (int) Math.Ceiling(cySpace * SysInfoStrings.Count));
  35.  
  36.           grfx.Dispose();
  37.      }
  38.      protected override void OnPaint(PaintEventArgs pea)
  39.      {
  40.           Graphics grfx       = pea.Graphics;
  41.           Brush    brush      = new SolidBrush(ForeColor);
  42.           int      iCount     = SysInfoStrings.Count;
  43.           string[] astrLabels = SysInfoStrings.Labels;
  44.           string[] astrValues = SysInfoStrings.Values;
  45.           Point    pt         = AutoScrollPosition;
  46.  
  47.           for (int i = 0; i < iCount; i++)
  48.           {
  49.                grfx.DrawString(astrLabels[i], Font, brush, 
  50.                                pt.X, pt.Y + i * cySpace);
  51.  
  52.                grfx.DrawString(astrValues[i], Font, brush, 
  53.                                pt.X + cxCol, pt.Y + i * cySpace); 
  54.           }
  55.      }
  56. }
  57.